package cn.crex1.kafka.consumer;

import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.messaging.handler.annotation.SendTo;
import org.springframework.stereotype.Component;

@Component
public class KafkaConsumer {

    @KafkaListener(id = "consumer-group-1",topics = {"topic1"})
    @SendTo("topic2")
    public String add(String message){
        System.out.println(message);
        return "转发到topic2 "+message;
    }

    @KafkaListener(id = "consumer-group-2",topics = {"topic2"})
    public void add3(String message){
        System.out.println("进入topic2");
        System.out.println(message);
    }

//    @KafkaListener(id = "consumer-group-1",topicPartitions = {
//            @TopicPartition(topic = "topic1",partitions = {"0","1"}),
//            @TopicPartition(topic = "topic2",partitions = {"0","2"},partitionOffsets = {@PartitionOffset(partition = "1",initialOffset = "10")})
//    },containerFactory = "kafkaListenerContainerFactory")
    public void add2(String message){
        System.out.println(message);
    }
}
